//
// C++ Implementation: tools
//
// Description: 
//
//
// Author: Cornelius Grimm,,, <cel@bean>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "tools.h"
#include <sha256.h>

std::basic_string<unsigned char> tools::sha256(const std::basic_string<unsigned char> & data)
{
    sha256_context ctx;
    sha256_starts(&ctx);
    sha256_update(&ctx, data.data(), data.length());
    unsigned char digest[32];
    sha256_finish(&ctx, digest);
    return std::basic_string<unsigned char>(digest, sizeof(digest));
}

std::string tools::hex(const std::basic_string<unsigned char> & data)
{
	std::string r;
	for(unsigned int i=0; i<data.size(); i++) {
		r += digits[data[i] / 16];
		r += digits[data[i] % 16];
	}
	return r;
}

char tools::digits [16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };

/*int tools::orientation(ExifData * data)
{
    if(data) {
        ExifEntry * entry = exif_content_get_entry(data->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION);
        if(entry) {
            char buf[1024];
            exif_entry_get_value(entry, buf, sizeof(buf));
            if(entry->format == EXIF_FORMAT_SHORT) {
                int o = exif_get_short(entry->data, exif_data_get_byte_order(data));
                switch(o) {
                case 1: return 0;
                case 6: return 1;
                case 3: return 2;
                case 8: return 3;
                }
            }
        }
    }
    return 0;
}*/
